package com.liqi.display.controller;

import com.liqi.display.common.Results;
import com.liqi.display.common.SystemCode;
import com.liqi.display.service.ITblAnnounceNumberService;
import com.liqi.display.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liqi
 * @since 2021-04-16
 */
@RestController
@RequestMapping("/tbl-announce-number")
public class TblAnnounceNumberController {

    @Autowired
    private ITblAnnounceNumberService announceNumberService;

    /**
     * 获取当月平均等待时长,通过取号时间、叫号时间做计算
     * @return
     */
    @GetMapping("getList")
    public Results getList(){
        Results results=new Results();
        try {
            //获取当前月的制定时间
            Date month = DateUtil.getMonth();
            long minutes = announceNumberService.getList(month);
            results.setData(minutes);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            return results;
        }catch (Exception e){
            results.setData(null);
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }
}
